﻿using Futuret.Core.Futuret;

namespace Future.Shared.Core;

/// <summary>
///     Author: Riva
///     Date: 2023/7/11 14:51
///     Description: 全局统一返回
/// </summary>
public class WebResult : UnifyResponse
{
    /// <summary>
    ///     成功
    /// </summary>
    /// <returns></returns>
    public static WebResult Success()
    {
        return Problem(CodeEnum.Success, "操作成功");
    }

    /// <summary>
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static WebResult Success(object? data)
    {
        return Problem(CodeEnum.Success, "操作成功", data);
    }

    /// <summary>
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static WebResult Success(string msg, object? data = default)
    {
        return Problem(CodeEnum.Success, msg, data);
    }

    /// <summary>
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static WebResult Error(string? msg = "操作失败")
    {
        return Problem(CodeEnum.Error, msg);
    }

    /// <summary>
    /// </summary>
    /// <param name="isBool"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static WebResult RetAppResult(bool isBool = true, object? data = default)
    {
        return isBool ? Success(data) : Error(data!.ToString());
    }

    /// <summary>
    /// </summary>
    /// <param name="status"></param>
    /// <param name="message"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static WebResult Problem(CodeEnum status, string? message = default, object? data = default)
    {
        return new WebResult { code = status, msg = message, data = data };
    }
}